<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Demo</title>
</head>

<body>
    <!--载入vue.js-->
    <script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>
    <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
    <div id="Application">
        您的名字是：{{data.name}} <br />
        您的ID是：{{data.id}}<br />
        您的年龄是：{{data.age}}<br />
        您的性别是：{{data.sex}}<br />
        <ul v-for="item in data.list">
            <li>{{item}}</li>
        </ul>
    </div>
    <script>
        const app = Vue.createApp({
            setup() {
                //存储数据
                const data = Vue.ref("");
                //对请求的开始进行拦截
                axios.interceptors.request.use(
                    (config) => {
                        alert("请求将要开始");
                        return config;
                    },
                    (error) => {
                        alert("请求出现错误");
                        return Promise.reject(error);
                    }
                );
                //请求完成后进行拦截
                axios.interceptors.response.use(
                    (response) => {
                        alert("请求完成，代码：" + response.status);
                        return response;
                    },
                    (error) => {
                        return Promise.reject(error);
                    }
                );

                //开始请求
                axios.get('https://rouse.npc.ink/api/data.php')
                    .then(response => {
                        data.value = response.data;
                    })

                return { data };

            },
        })

        app.mount("#Application")
    </script>
</body>

</html>